package com.koron.css2.projectCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.projectCenter.bean.query.PjInternalQueryBean;
import com.koron.css2.projectCenter.mapper.PjInternalMapper;
import com.koron.css2.projectCenter.vo.PjInternalListVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;

/**
 * 内部工程单列表
 * @author 梁光春
 */
public class PjInternalList implements ServerInterface {

	private static Logger logger = LogManager.getLogger(PjInternalList.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
		MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", PageInfo.class);

		try {
			//入参转成queryBean
			PjInternalQueryBean bean = JsonUtils.objectToPojo(req.getData(), PjInternalQueryBean.class);
			//设置分页参数
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			
			PjInternalMapper mapper = factory.getMapper(PjInternalMapper.class);
			
			//获取数据字典
			Map<String, String> EGD = Tools.mapDicByCode(factory, "EGD");
			//获取工程单数据
			List<PjInternalListVO> list = mapper.selectList(bean);
			//转换状态字段
			for(PjInternalListVO pbean:list) {
				//转换数据字典
				pbean.setUrgentFlagName(EGD.get(pbean.getUrgentFlag()));
				//pbean.setProcessState(Tools.transProcessStatus(pbean.getProcessState()));
			}

			info.setData(new PageInfo<>(list));
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error("内部工程单列表查询失败"+e.getMessage(), e);
		}
		return info;
	}

}
